package com.breeze.blockchain.common.init;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.breeze.components.core.ServiceInfo;
import com.breeze.components.web.warm.WarmProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 预热配置
 *
 * @author breeze
 */
@Slf4j
@Configuration
public class WarmRunnerConfig {

  @Bean
  public WarmProcessor warmProcessor() {
    return new WarmProcessor(
        () -> {
          log.info(
              "请求本机健康检查接口：{}",
              HttpUtil.get(
                  StrUtil.format(
                      "http://localhost:{}/actuator/health", ServiceInfo.getActuatorPort())));
          log.info(
              "请求本机健康检查接口(就绪探针)：{}",
              HttpUtil.get(
                  StrUtil.format(
                      "http://localhost:{}/actuator/health/readiness",
                      ServiceInfo.getActuatorPort())));
          log.info(
              "请求本机健康检查接口(存活探针)：{}",
              HttpUtil.get(
                  StrUtil.format(
                      "http://localhost:{}/actuator/health/liveness",
                      ServiceInfo.getActuatorPort())));
        });
  }
}
